package com.ruoyi.project.applet.controller;

import java.util.List;

import com.ruoyi.project.system.domain.SysUserWx;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.applet.domain.Wallelog;
import com.ruoyi.project.applet.service.IWallelogService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 钱包记录Controller
 *
 * @author ruoyi
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/applet/log")
public class WallelogController extends BaseController {
    @Autowired
    private IWallelogService wallelogService;


    @GetMapping("/list")
    public TableDataInfo list(Wallelog wallelog) {
        startPage();
        List<Wallelog> list = wallelogService.selectWallelogList(wallelog);
        return getDataTable(list);
    }

    @GetMapping("/profit")
    public AjaxResult profit(@RequestParam String startTime, @RequestParam String endTime, @RequestParam String status) {

        SysUserWx userWx = getLoginUser().getUserWx();
//        final SysUserWx userWx = sysUserWxService.selectSysUserWxByOpenId("opzDn5b3ylWXuGzg52E4UjaTDLzw");

        return wallelogService.profit(startTime, endTime, status, userWx);
    }




    @GetMapping("/take")
    public AjaxResult take() {
        SysUserWx userWx = getLoginUser().getUserWx();
        return wallelogService.take(userWx);
    }

    @GetMapping("/take/log")
    public AjaxResult takeLog() {
        SysUserWx userWx = getLoginUser().getUserWx();
        return wallelogService.takeLog(userWx);
    }


    @Log(title = "钱包记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Wallelog wallelog) {
        List<Wallelog> list = wallelogService.selectWallelogList(wallelog);
        ExcelUtil<Wallelog> util = new ExcelUtil<Wallelog>(Wallelog.class);
        return util.exportExcel(list, "log");
    }


    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(wallelogService.selectWallelogById(id));
    }


    @Log(title = "钱包记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wallelog wallelog) {
        return toAjax(wallelogService.insertWallelog(wallelog));
    }


    @Log(title = "钱包记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wallelog wallelog) {
        return toAjax(wallelogService.updateWallelog(wallelog));
    }

    /**
     * 删除钱包记录
     */
    @Log(title = "钱包记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wallelogService.deleteWallelogByIds(ids));
    }
}
